package logic

import (
	"context"
	"cp/cprpc/cprpc"
	"cp/cprpc/internal/svc"
	"cp/models/mysql"
	"github.com/zeromicro/go-zero/core/logx"
)

type CollectionAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectionAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectionAddLogic {
	return &CollectionAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectionAddLogic) CollectionAdd(in *cprpc.CollectionAddRequest) (*cprpc.CollectionAddResponse, error) {
	// todo: add your logic here and delete this line

	collection := mysql.Collection{
		UserId:   int(in.UserId),
		CourseId: int(in.CourseId),
		Status:   in.Status,
	}
	mysql.DB.Debug().Create(&collection)

	return &cprpc.CollectionAddResponse{
		CollectionId: int64(collection.ID),
	}, nil
}
